<template>
    <div>
        <el-input v-model="neName" style="width: 240px" placeholder="请输入新员工名字"></el-input>
        <el-button type="primary" @click="reset">添加员工</el-button>
    </div>
</template>
<script>
import {ref} from "vue";
import {urls} from "@/api/api";
import {postP} from "@/api/request";
import {ElMessage, ElMessageBox} from "element-plus";


export default {
    setup() {
        const neName = ref()
        const reset = async () => {
            if(neName.value.trim() === ""){
                ElMessage({
                    type: 'error',
                    message: `用户名不能为空 `,
                })
                return
            }

            await ElMessageBox.alert('确定添加员工', '提示', {
                confirmButtonText: '确定',
                callback: () => {
                    ElMessage({
                        type: 'success',
                        message: `员工添加成功`,
                    })
                },
            })
            try {
                console.log(neName.value)
                const response = await postP(urls.m().addInfo,{neName:neName.value})
                console.log(response)
            } catch (error) {
                console.log(error)
            }
        }
        return {
            neName, reset
        }
    }
}
</script>